<?

if ($DATA['component']['id']) {

	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value
	$_values			= array('title');	// which fields are stored in language variations

	// get current date
	$DATA['today'] = parse_today();
	
	if (!($dt = param('date')) || !($dt = parse_date($dt)) ) 		// get date from param (y2k-YY-MM-DD) if correct, elsewere get current date
		$dt = $DATA['today'];
	
	$DATA['date'] = $dt;

	$_crit = "id_data=$_id_data AND id_parent=$_id_component AND DATE(date)='{$DATA[date][full]}'";


	$_defaults = array('id_data' => D_MB_DATA, 'id_parent' => $DATA['component']['id'], 'date' => $DATA['date']['full']);
																										  
	switch (action(array('editor_save'))) {
	
		case 'editor_save':
		
			$temp = array();
			foreach($DATA['langs'] as $lang) {
			
				foreach($_values as $name) {
				
					$t = postdata($name);
					if ($tx = trim($t[$lang['text']]))
						$temp[] = array_merge($_defaults, array('name' => $name, 'value' => $tx, 'assoc' => $lang['text']));
				}
				
				takeImage($_FILES['image'][$lang['text']], $s['w'], $s['h'], "$s[path]$lang[text]-{$DATA[date][full]}");
			}

			dataset('db_delete', tb('data'), "id_data=$_id_data AND id_parent={$DATA[component][id]} AND DATE(date)='{$DATA[date][full]}'");
			dataset('db_insert', tb('data'), $temp);

			return _transformURL($CURRENT->url, array('remove_param' => 'date'));	// end of component edition
			
			break;
	}
	
	$DATA['daily'] = array();
	foreach( datafetch_array('db_list', array('table' => tb('data'), 'where' => $_crit)) as $v)
		$DATA['daily'][$v['assoc']][$v['name']] = $v['value'];

	foreach($DATA['langs'] as $lang) {
		$DATA['daily'][$lang['text']]['image'] = checkImage("$s[path]$lang[text]-{$DATA[date][full]}");
		
debug($DATA['daily']);

	return false;

} else exit;

?>